package com.revengemission.sso.oauth2.server.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.security.Principal;

@Controller
public class HomeController {

    @GetMapping(value = {"", "/"})
    public String home(Principal principal, Model model) {
        if (principal == null) {
            // 未登录，重定向到登录页面
            return "redirect:/signIn";
        }
        
        // 已登录，显示首页
        model.addAttribute("username", principal.getName());
        return "home";
    }

    @GetMapping(value = "/profile-image")
    public String profileImage(Principal principal, Model model) {
        if (principal == null) {
            // 未登录，重定向到登录页面
            return "redirect:/signIn";
        }
        
        model.addAttribute("username", principal.getName());
        return "profile";
    }
} 